package com.woniuxy.oa.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.oa.entity.Goods_purchase;
import com.woniuxy.oa.entity.PageBean;
import com.woniuxy.oa.mapper.Approval_goodsclaimMapper;
import com.woniuxy.oa.mapper.Approval_goodspurchaseMapper;
import com.woniuxy.oa.mapper.GoodsRepositoryMapper;
import com.woniuxy.oa.mapper.Goods_purchaseMapper;
import com.woniuxy.oa.service.Goods_purchaseService;
@Service
public class Goods_purchaseServiceImpl implements Goods_purchaseService{
	
	@Autowired
	Goods_purchaseMapper goods_purchaseMapper;
	@Autowired
	GoodsRepositoryMapper goodsRepositoryMapper;
	@Autowired
	Approval_goodspurchaseMapper approval_goodspurchaseMapper;
	
	
	@Override
	public void addPurchaseGetGp_id(Goods_purchase goods_purchase) {
		try {
			goods_purchaseMapper.insertPurchaseGetGp_id(goods_purchase);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		//获取插入信息的主键列
//		Integer s_id=goods_purchase.getGp_id();
//		Integer gp_status = goods_purchase.getGp_status();
//		String gp_name = goods_purchase.getGp_name();
//		Integer gp_number = goods_purchase.getGp_number();
//		if(gp_status==1) {
//			//判断库存里有没有此物品
//			Integer gr_number = goodsRepositoryMapper.selectGr_numberByGr_name(gp_name);
//			if(gr_number ==null) {
//				//往库存添加数据
//				goodsRepositoryMapper.insertGoodsRepository(gp_name,gp_number,s_id);
//			}else {
//				//增加库存数量
//				goodsRepositoryMapper.updateAddGr_numberByGr_name(gp_number, gp_name);
//			}
//		}
	}

	@Override
	public void modifyPurchaseByGp_id(Goods_purchase goods_purchase) {
		goods_purchaseMapper.updatePurchaseByGp_id(goods_purchase);
		
	}

	@Override
	public void removePuchaseByGp_id(Integer gp_id) {
		goods_purchaseMapper.deletePuchaseByGp_id(gp_id);
		//删除对应关系表
		approval_goodspurchaseMapper.deleteApproval_goodspurchase(gp_id);
	}

	@Override
	public Goods_purchase selectGoods_purchaseByGp_id(Integer gp_id) {
		Goods_purchase goods_purchase = goods_purchaseMapper.selectGoods_purchaseByGp_id(gp_id);
		return goods_purchase;
	}

	
	@Override
	public PageBean<Goods_purchase> getGoods_purchaseByPage(String name, Integer pageIndex, Integer pageSize) {
		List<Goods_purchase> beanList = goods_purchaseMapper.selectGoods_purchaseConditionByName(name, (pageIndex-1)*pageSize, pageSize);
		Integer totalRecord = goods_purchaseMapper.selectGoods_purchaseTotalRecordById(name);
		PageBean<Goods_purchase> pb=new PageBean<Goods_purchase>();
		pb.setBeanList(beanList);
		pb.setPageIndex(pageIndex);
		pb.setPageSize(pageSize);
		pb.setTotalRecord(totalRecord);
		pb.setPageBeginAndPageEnd();
		return pb;
	}

	

}
